<extend name="Public:index" />
<block name="mycss">
    <link href="__PUBLIC__/assets/plugins/select2/select2.min.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .inputx {
            width: 70%;
            height: 34px;
        }
    </style>
</block>
<block name="main-content">
    <iframe name="ajaxifr" style="display:none;"></iframe>
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <form id="add_form" name="add_form" action="__ACTION__" method="post" class="definewidth m20"
                            target="ajaxifr">
                            <table class="table table-bordered table-hover definewidth m10">
                                <tr>
                                    <td width="15%">用户名：</td>
                                    <td>
                                        <input class="inputx" type="text" name="username" id="username" value="{$vo.username}" />
                                        <b style="color:#CE0000;">*</b>
                                        <span id="namat">(3-30个字符，可用汉字，字母或数字)</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td>公司名称：</td>
                                    <td>
                                        <input class="inputx" type="text" name="company" id="company" value="{$vo.company}" />
                                        <b style="color:#CE0000;">*</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Email：</td>
                                    <td>
                                        <input class="inputx" type="email" name="email" id="email" value="{$vo.email}" />
                                        <b style="color:#CE0000;">*</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>手机号：</td>
                                    <td>
                                        <input class="inputx" type="text" name="phone" id="phone" value="{$vo.phone}" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>账号状态：</td>
                                    <td>
                                        <div class="custom-control custom-radio">
                                            <input type="radio" id="shenhe" name="isforbidden" class="custom-control-input"
                                                value="0" {$vo['isforbidden']==0 ? 'checked' : '' }>
                                            <label class="custom-control-label" for="shenhe">启用</label>
                                        </div>
                                        <div class="custom-control custom-radio">
                                            <input type="radio" id="shenhe1" name="isforbidden" class="custom-control-input"
                                                value="1" {$vo['isforbidden']==1 ? 'checked' : '' }>
                                            <label class="custom-control-label" for="shenhe1">禁用</label>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否项目管理员：</td>
                                    <td>
                                        <div class="custom-control custom-radio">
                                            <input type="radio" id="isadmin" name="is_admin" class="custom-control-input"
                                                value="1" {$vo['is_admin']==1 ? 'checked' : '' }>
                                            <label class="custom-control-label" for="isadmin">是</label>
                                        </div>
                                        <div class="custom-control custom-radio">
                                            <input type="radio" id="isadmin1" name="is_admin" class="custom-control-input"
                                                value="0" {$vo['is_admin']==0 ? 'checked' : '' }>
                                            <label class="custom-control-label" for="isadmin1">否</label>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>项目数量：</td>
                                    <td>
                                        <input class="inputx" type="number" name="project_num" id="project_num" value="{$vo.project_num}" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>模版包：</td>
                                    <td>
                                        <select id="select2" name="module_ids[]" class="form-control" multiple>
                                            <option value="0">请选择</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>角色：</td>
                                    <td>
                                        <select id="rootid" name="roleid" class="inputx">
                                            <option value="">请选择</option>
                                            <volist name="roleData" id="r">
                                                <option value="{$r[roleid]}" {$vo['roleid']==$r['roleid'] ? 'selected'
                                                    : '' }>{$r[rolename]}</option>
                                            </volist>
                                        </select>
                                        &nbsp;&nbsp;<b style="color:#CE0000;">*</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <input type="hidden" id="userid" name="userid" value="{$vo.userid}" />
                                        <input type="hidden" name="act" value="{$vo['userid'] ? 'edit' : 'add'}" />
                                        <input type="hidden" name="old_role_id" value="{$vo.roleid}">
                                        <input type="submit" class="btn btn-primary" id="sub" name="sub" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="reset" class="btn btn-success" value="清空" />
                                    </td>
                                </tr>
                            </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </form>
</block>
<block name="myscript">
    <script src="__PUBLIC__/assets/js/jquery.validate.js"></script>
    <script src="__PUBLIC__/assets/plugins/select2/select2.min.js"></script>
    <script>

        //select2 control
        $('#select2').select2({
            placeholder: '选择模版包...',
            tags: true,
            ajax: {
                url: "{:U('getModule','','')}",
                dataType: 'json',
                delay: 250  // wait 250 milliseconds before triggering the request
            }
        });
        //清除所有当前选项
        //$('.select2').val(null).trigger('change');

        var userid = $('#userid').val();
        // Fetch the preselected item, and add to the control
        var selectObj = $('#select2');
        $.ajax({
            type: 'GET',
            url: '{:U('getSelModule','','')}/userid/' + userid
        }).then(function (data) {
            // create the option and append to Select2
            for (var rs of data.results) {
                var option = new Option(rs.text, rs.id, true, true);
                selectObj.append(option).trigger('change');
            }
            // manually trigger the `select2:select` event
            selectObj.trigger({
                type: 'select2:select',
                params: {
                    data: data
                }
            });
        });

    </script>
</block>